
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module apiclient.http</title>
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="apiclient.html"><font color="#ffffff">apiclient</font></a>.http</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/http.py">/usr/local/google/home/jcgregorio/projects/apiclient/apiclient/http.py</a></font></td></tr></table>
    <p><tt>Classes&nbsp;to&nbsp;encapsulate&nbsp;a&nbsp;single&nbsp;HTTP&nbsp;request.<br>
&nbsp;<br>
The&nbsp;classes&nbsp;implement&nbsp;a&nbsp;command&nbsp;pattern,&nbsp;with&nbsp;every<br>
<a href="__builtin__.html#object">object</a>&nbsp;supporting&nbsp;an&nbsp;execute()&nbsp;method&nbsp;that&nbsp;does&nbsp;the<br>
actuall&nbsp;HTTP&nbsp;request.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="httplib2.html">httplib2</a><br>
</td><td width="25%" valign=top><a href="os.html">os</a><br>
</td><td width="25%" valign=top><a href="simplejson.html">simplejson</a><br>
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
    
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="apiclient.http.html#HttpRequest">HttpRequest</a>
</font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#RequestMockBuilder">RequestMockBuilder</a>
</font></dt></dl>
</dd>
</dl>
 <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="HttpRequest">class <strong>HttpRequest</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>Encapsulates&nbsp;a&nbsp;single&nbsp;HTTP&nbsp;request.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="HttpRequest-__init__"><strong>__init__</strong></a>(self, http, postproc, uri, method<font color="#909090">='GET'</font>, body<font color="#909090">=None</font>, headers<font color="#909090">=None</font>, methodId<font color="#909090">=None</font>)</dt><dd><tt>Constructor&nbsp;for&nbsp;an&nbsp;<a href="#HttpRequest">HttpRequest</a>.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;http:&nbsp;httplib2.Http,&nbsp;the&nbsp;transport&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;to&nbsp;use&nbsp;to&nbsp;make&nbsp;a&nbsp;request<br>
&nbsp;&nbsp;postproc:&nbsp;callable,&nbsp;called&nbsp;on&nbsp;the&nbsp;HTTP&nbsp;response&nbsp;and&nbsp;content&nbsp;to&nbsp;transform<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;it&nbsp;into&nbsp;a&nbsp;data&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;before&nbsp;returning,&nbsp;or&nbsp;raising&nbsp;an&nbsp;exception<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on&nbsp;an&nbsp;error.<br>
&nbsp;&nbsp;uri:&nbsp;string,&nbsp;the&nbsp;absolute&nbsp;URI&nbsp;to&nbsp;send&nbsp;the&nbsp;request&nbsp;to<br>
&nbsp;&nbsp;method:&nbsp;string,&nbsp;the&nbsp;HTTP&nbsp;method&nbsp;to&nbsp;use<br>
&nbsp;&nbsp;body:&nbsp;string,&nbsp;the&nbsp;request&nbsp;body&nbsp;of&nbsp;the&nbsp;HTTP&nbsp;request<br>
&nbsp;&nbsp;headers:&nbsp;dict,&nbsp;the&nbsp;HTTP&nbsp;request&nbsp;headers<br>
&nbsp;&nbsp;methodId:&nbsp;string,&nbsp;a&nbsp;unique&nbsp;identifier&nbsp;for&nbsp;the&nbsp;API&nbsp;method&nbsp;being&nbsp;called.</tt></dd></dl>

<dl><dt><a name="HttpRequest-execute"><strong>execute</strong></a>(self, http<font color="#909090">=None</font>)</dt><dd><tt>Execute&nbsp;the&nbsp;request.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;http:&nbsp;httplib2.Http,&nbsp;an&nbsp;http&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;to&nbsp;be&nbsp;used&nbsp;in&nbsp;place&nbsp;of&nbsp;the<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;one&nbsp;the&nbsp;<a href="#HttpRequest">HttpRequest</a>&nbsp;request&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;was&nbsp;constructed&nbsp;with.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;A&nbsp;deserialized&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;model&nbsp;of&nbsp;the&nbsp;response&nbsp;body&nbsp;as&nbsp;determined<br>
&nbsp;&nbsp;by&nbsp;the&nbsp;postproc.<br>
&nbsp;<br>
Raises:<br>
&nbsp;&nbsp;apiclient.errors.HttpError&nbsp;if&nbsp;the&nbsp;response&nbsp;was&nbsp;not&nbsp;a&nbsp;2xx.<br>
&nbsp;&nbsp;httplib2.Error&nbsp;if&nbsp;a&nbsp;transport&nbsp;error&nbsp;has&nbsp;occured.</tt></dd></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="RequestMockBuilder">class <strong>RequestMockBuilder</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>A&nbsp;simple&nbsp;mock&nbsp;of&nbsp;<a href="#HttpRequest">HttpRequest</a><br>
&nbsp;<br>
Pass&nbsp;in&nbsp;a&nbsp;dictionary&nbsp;to&nbsp;the&nbsp;constructor&nbsp;that&nbsp;maps&nbsp;request&nbsp;methodIds&nbsp;to<br>
tuples&nbsp;of&nbsp;(httplib2.Response,&nbsp;content,&nbsp;opt_expected_body)&nbsp;that&nbsp;should&nbsp;be<br>
returned&nbsp;when&nbsp;that&nbsp;method&nbsp;is&nbsp;called.&nbsp;None&nbsp;may&nbsp;also&nbsp;be&nbsp;passed&nbsp;in&nbsp;for&nbsp;the<br>
httplib2.Response,&nbsp;in&nbsp;which&nbsp;case&nbsp;a&nbsp;200&nbsp;OK&nbsp;response&nbsp;will&nbsp;be&nbsp;generated.<br>
If&nbsp;an&nbsp;opt_expected_body&nbsp;(str&nbsp;or&nbsp;dict)&nbsp;is&nbsp;provided,&nbsp;it&nbsp;will&nbsp;be&nbsp;compared&nbsp;to<br>
the&nbsp;body&nbsp;and&nbsp;UnexpectedBodyError&nbsp;will&nbsp;be&nbsp;raised&nbsp;on&nbsp;inequality.<br>
&nbsp;<br>
Example:<br>
&nbsp;&nbsp;response&nbsp;=&nbsp;'{"data":&nbsp;{"id":&nbsp;"tag:google.c...'<br>
&nbsp;&nbsp;requestBuilder&nbsp;=&nbsp;<a href="#RequestMockBuilder">RequestMockBuilder</a>(<br>
&nbsp;&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'chili.activities.get':&nbsp;(None,&nbsp;response),<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;)<br>
&nbsp;&nbsp;apiclient.discovery.build("buzz",&nbsp;"v1",&nbsp;requestBuilder=requestBuilder)<br>
&nbsp;<br>
Methods&nbsp;that&nbsp;you&nbsp;do&nbsp;not&nbsp;supply&nbsp;a&nbsp;response&nbsp;for&nbsp;will&nbsp;return&nbsp;a<br>
200&nbsp;OK&nbsp;with&nbsp;an&nbsp;empty&nbsp;string&nbsp;as&nbsp;the&nbsp;response&nbsp;content&nbsp;or&nbsp;raise&nbsp;an&nbsp;excpetion&nbsp;if<br>
check_unexpected&nbsp;is&nbsp;set&nbsp;to&nbsp;True.&nbsp;The&nbsp;methodId&nbsp;is&nbsp;taken&nbsp;from&nbsp;the&nbsp;rpcName<br>
in&nbsp;the&nbsp;discovery&nbsp;document.<br>
&nbsp;<br>
For&nbsp;more&nbsp;details&nbsp;see&nbsp;the&nbsp;project&nbsp;wiki.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="RequestMockBuilder-__call__"><strong>__call__</strong></a>(self, http, postproc, uri, method<font color="#909090">='GET'</font>, body<font color="#909090">=None</font>, headers<font color="#909090">=None</font>, methodId<font color="#909090">=None</font>)</dt><dd><tt>Implements&nbsp;the&nbsp;callable&nbsp;interface&nbsp;that&nbsp;discovery.build()&nbsp;expects<br>
of&nbsp;requestBuilder,&nbsp;which&nbsp;is&nbsp;to&nbsp;build&nbsp;an&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;compatible&nbsp;with<br>
<a href="#HttpRequest">HttpRequest</a>.execute().&nbsp;See&nbsp;that&nbsp;method&nbsp;for&nbsp;the&nbsp;description&nbsp;of&nbsp;the<br>
parameters&nbsp;and&nbsp;the&nbsp;expected&nbsp;response.</tt></dd></dl>

<dl><dt><a name="RequestMockBuilder-__init__"><strong>__init__</strong></a>(self, responses, check_unexpected<font color="#909090">=False</font>)</dt><dd><tt>Constructor&nbsp;for&nbsp;<a href="#RequestMockBuilder">RequestMockBuilder</a><br>
&nbsp;<br>
The&nbsp;constructed&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;should&nbsp;be&nbsp;a&nbsp;callable&nbsp;<a href="__builtin__.html#object">object</a><br>
that&nbsp;can&nbsp;replace&nbsp;the&nbsp;class&nbsp;HttpResponse.<br>
&nbsp;<br>
responses&nbsp;-&nbsp;A&nbsp;dictionary&nbsp;that&nbsp;maps&nbsp;methodIds&nbsp;into&nbsp;tuples<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;of&nbsp;(httplib2.Response,&nbsp;content).&nbsp;The&nbsp;methodId<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;comes&nbsp;from&nbsp;the&nbsp;'rpcName'&nbsp;field&nbsp;in&nbsp;the&nbsp;discovery<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.<br>
check_unexpected&nbsp;-&nbsp;A&nbsp;boolean&nbsp;setting&nbsp;whether&nbsp;or&nbsp;not&nbsp;UnexpectedMethodError<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;should&nbsp;be&nbsp;raised&nbsp;on&nbsp;unsupplied&nbsp;method.</tt></dd></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
    
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt><a name="-tunnel_patch"><strong>tunnel_patch</strong></a>(http)</dt><dd><tt>Tunnel&nbsp;PATCH&nbsp;requests&nbsp;over&nbsp;POST.<br>
Args:<br>
&nbsp;&nbsp;&nbsp;http&nbsp;-&nbsp;An&nbsp;instance&nbsp;of&nbsp;httplib2.Http<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or&nbsp;something&nbsp;that&nbsp;acts&nbsp;like&nbsp;it.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;A&nbsp;modified&nbsp;instance&nbsp;of&nbsp;http&nbsp;that&nbsp;was&nbsp;passed&nbsp;in.<br>
&nbsp;<br>
Example:<br>
&nbsp;<br>
&nbsp;&nbsp;h&nbsp;=&nbsp;httplib2.Http()<br>
&nbsp;&nbsp;h&nbsp;=&nbsp;<a href="#-tunnel_patch">tunnel_patch</a>(h,&nbsp;"my-app-name/6.0")<br>
&nbsp;<br>
Useful&nbsp;if&nbsp;you&nbsp;are&nbsp;running&nbsp;on&nbsp;a&nbsp;platform&nbsp;that&nbsp;doesn't&nbsp;support&nbsp;PATCH.<br>
Apply&nbsp;this&nbsp;last&nbsp;if&nbsp;you&nbsp;are&nbsp;using&nbsp;OAuth&nbsp;1.0,&nbsp;as&nbsp;changing&nbsp;the&nbsp;method<br>
will&nbsp;result&nbsp;in&nbsp;a&nbsp;different&nbsp;signature.</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
    
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>__all__</strong> = ['HttpRequest', 'RequestMockBuilder', 'HttpMockset_user_agent', 'tunnel_patch']<br>
<strong>__author__</strong> = 'jcgregorio@google.com (Joe Gregorio)'</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#7799ee">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
    
<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%">jcgregorio@google.com&nbsp;(Joe&nbsp;Gregorio)</td></tr></table>
</body></html>